package com.ruoyi.project.anquan.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.anquan.domain.SecuritySgsj;
import com.ruoyi.project.anquan.service.ISecuritySgsjService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 事故事件Controller
 * 
 * @author ruoyi
 * @date 2020-05-11
 */
@RestController
@RequestMapping("/anquan/sgsj")
public class SecuritySgsjController extends BaseController
{
    @Autowired
    private ISecuritySgsjService securitySgsjService;

    /**
     * 查询事故事件列表
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:list')")
    @GetMapping("/list")
    public TableDataInfo list(SecuritySgsj securitySgsj)
    {
        startPage();
        List<SecuritySgsj> list = securitySgsjService.selectSecuritySgsjList(securitySgsj);
        return getDataTable(list);
    }

    /**
     * 导出事故事件列表
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:export')")
    @Log(title = "事故事件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SecuritySgsj securitySgsj)
    {
        List<SecuritySgsj> list = securitySgsjService.selectSecuritySgsjList(securitySgsj);
        ExcelUtil<SecuritySgsj> util = new ExcelUtil<SecuritySgsj>(SecuritySgsj.class);
        return util.exportExcel(list, "sgsj");
    }

    /**
     * 获取事故事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:query')")
    @GetMapping(value = "/{sgsjId}")
    public AjaxResult getInfo(@PathVariable("sgsjId") Long sgsjId)
    {
        return AjaxResult.success(securitySgsjService.selectSecuritySgsjById(sgsjId));
    }

    /**
     * 新增事故事件
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:add')")
    @Log(title = "事故事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SecuritySgsj securitySgsj)
    {
        return toAjax(securitySgsjService.insertSecuritySgsj(securitySgsj));
    }

    /**
     * 修改事故事件
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:edit')")
    @Log(title = "事故事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SecuritySgsj securitySgsj)
    {
        return toAjax(securitySgsjService.updateSecuritySgsj(securitySgsj));
    }

    /**
     * 删除事故事件
     */
    @PreAuthorize("@ss.hasPermi('anquan:sgsj:remove')")
    @Log(title = "事故事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sgsjIds}")
    public AjaxResult remove(@PathVariable Long[] sgsjIds)
    {
        return toAjax(securitySgsjService.deleteSecuritySgsjByIds(sgsjIds));
    }
}
